/**
 * 
 */
package com.alessandrodonato.elledia.model;

import java.io.Serializable;
import java.util.ArrayList;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.springframework.format.annotation.DateTimeFormat;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * @author Alessandro Donato
 *
 * 06/feb/2013
*/

/*
	@Entity annotation is used to declare the POJO as persistent entity.
	@Table annotation is used to map the POJO class to the table. In our case it is 'certificato' table in database.
	@Id represents the identifier property.
	@GeneratedValue declares that the identifier value will be generated by the database automatically. 
	@Column is used to map the property to the column of the table.
*/

@Entity
@Table	(name = "certificato", catalog = "elledia", 
				uniqueConstraints = {
						@UniqueConstraint(columnNames = "ID"),
						@UniqueConstraint(columnNames = "CODICE") })
public class Certificato implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6686006605735540543L;
	
	private int id;
	private String codice;
	
	@DateTimeFormat(pattern = "dd/MM/yyyy")
	private java.util.Date data;
	private int idFornitore;
	private Fornitore fornitore;
	
	private byte [] fileContent;
	private String filenName;
	private long fileLength;
	
	private ArrayList<Materiale> materiali;

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	@Id
	@GeneratedValue (strategy = IDENTITY)
	@Column (name = "ID",unique = true, nullable = false)
	public int getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(name = "CODICE", unique = true, nullable = false, length = 10)
	public String getCodice() {
		return codice;
	}

	public void setCodice(String codice) {
		this.codice = codice;
	}
	
	@Column(name = "DATA")
	public java.util.Date getData() {
		return data;
	}
	
	public void setData(java.util.Date data) {
		this.data = data;
	}
	
	@ManyToOne
	public Fornitore getFornitore() {
		return fornitore;
	}

	public void setFornitore(Fornitore fornitore) {
		this.fornitore = fornitore;
	}
	
	public byte[] getFileContent() {
		return fileContent;
	}

	public void setFileContent(byte[] fileContent) {
		this.fileContent = fileContent;
	}

	public String getFileName() {
		return filenName;
	}

	public void setFileName(String filenName) {
		this.filenName = filenName;
	}

	public long getFileLength() {
		return fileLength;
	}

	public void setFileLength(long fileLength) {
		this.fileLength = fileLength;
	}

	public String toString () {
		return "Certificato [id=" + id + ", codice=" + codice + "]";
	}

	@OneToMany(mappedBy = "certificato")
	public ArrayList<Materiale> getMateriali() {
		return materiali;
	}

	public void setMateriali(ArrayList<Materiale> materiali) {
		this.materiali = materiali;
	}

	public int getIdFornitore() {
		return idFornitore;
	}

	public void setIdFornitore(int idFornitore) {
		this.idFornitore = idFornitore;
	}

	
}
